<template>
  <div class="login-wrap">
    <div class="left-context">
      <img
        src="../assets/img/undraw_login_re_4vu2_1.png"
        alt=""
        class="login-img"
      />
    </div>
    <div class="right-context">
      <div class="context-text">欢迎注册创思设备管理系统</div>
      <div class="context-login">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
          姓名
          <el-form-item prop="username">
            <el-input v-model="ruleForm.username"></el-input>
          </el-form-item>
          邮箱
          <el-form-item prop="email">
            <el-input v-model="ruleForm.email"></el-input>
          </el-form-item>
          密码
          <el-form-item prop="password">
            <el-input type="password" v-model="ruleForm.password">
              <i
                slot="suffix"
                :class="[flag ? 'el-icon-view' : 'el-icon-minus']"
                style="margin-top: 8px; font-size: 18px"
                autocomplete="auto"
                @click="flag = !flag"
              />
            </el-input>
          </el-form-item>

          <el-checkbox v-model="ruleForm.checked"
            >我已阅读用户协议并同意</el-checkbox
          >

          <el-form-item style="width: 100%">
            <el-button
              size="medium"
              type="primary"
              class="register-btn"
              @click="registerGo"
              >注册</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <div class="jump-register">
        您已由平台账号？
        <el-button type="text" @click="loginForm">用户登录</el-button>
        <el-button class="forget-pwd" type="text" @click="resetpwdForm"
          >忘记密码</el-button
        >
      </div>
    </div>
  </div>
</template>
<script>
import { mixin } from "../mixins/index";
import { setRegisterGo } from "../api/index";
export default {
  mixins: [mixin],
  data: function () {
    return {
      flag: false,
      ruleForm: {
        username: "",
        email: "",
        password: "",
        checked: false,
      },
      rules: {
        username: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        email: [{ required: true, message: "请输入邮箱", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    registerGo() {
      let params = new URLSearchParams();
      params.append("username", this.ruleForm.username);
      params.append("email", this.ruleForm.email);
      params.append("password", this.ruleForm.password);
      setRegisterGo(params).then((res) => {
        if (res.code === 1) {
          this.notify("注册成功，请重新登录", "success");
        } else {
          this.notify("注册失败", "error");
        }
      });
    },
    loginForm() {
      this.$router.push("/");
    },
    resetpwdForm() {
      this.$router.push("/resetpwd");
    },
  },
};
</script>
<style scoped>
.login-wrap {
  width: 1024px;
  height: 600px;
  margin: 6% 0 0 20%;
  background-color: #fff;
}
.login-img {
  width: 350px;
  height: 200px;
  margin: 180px 0 0 80px;
}
.left-context {
  float: left;
  width: 512px;
  height: 600px;
  background-color: #9a9aeb;
}
.right-context {
  position: relative;
  float: right;
  width: 512px;
  height: 600px;
}
.context-text {
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  margin-top: 50px;
}
.context-login {
  position: absolute;
  width: 350px;
  height: 280px;
  margin-left: 95px;
  margin-top: 20px;
}
.register-btn {
  width: 100%;
  background-color: #1e1e1e;
  border-radius: 5px;
  margin-top: 20px;
}
.jump-register {
  margin: 400px 0 0 100px;
  font-size: 14px;
}
.forget-pwd {
  margin-left: 90px;
  color: #000;
}
</style>
